<?php
if ( IPB_THIS_SCRIPT != 'admin' )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'init.php'.";
	exit();
}

class ad_logs
{
	var $ipsclass;
	var $LIMIT = 50;
	var $IP_LIMIT = 25;
	
	function auto_run()
	{
		$redirect = array(
							'receipt' => 'receipt',
							'item' => 'item',
							'reward' => 'reward',
							'fee' => 'fee',
							'ip' => 'ip_address_search',
						);
		
		if(!isset($redirect[$this->ipsclass->input['do']]))
		{
			$this->ipsclass->input['do'] = 'reward';
		}
		
		$func = $redirect[$this->ipsclass->input['do']].'_logs';
		$this->$func();
	}
	
	function receipt_logs()
	{
		$this->ipsclass->DB->load_cache_file(ROOT_PATH.'sources/market/'.$this->ipsclass->vars['sql_driver'].'_market_queries.php','sql_market_queries');
		
		$this->ipsclass->input['st'] = intval($this->ipsclass->input['st']);
		
		$this->ipsclass->admin->page_title  = "Welcome to receipts page";
		$this->ipsclass->admin->page_detail = "Welcome to receipts page.";
		$this->ipsclass->admin->nav[] 		= array( $this->ipsclass->form_code.'&amp;code=logs&amp;do=receipt', 'Receipts' );
		
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'market_buy_logs','group'=>'time_bought, method, member_id'));
		$this->ipsclass->DB->exec_query();
		$total_count = $this->ipsclass->DB->get_num_rows();
		
		$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total_count,
																	'PER_PAGE'     => $this->LIMIT,
																	'USE_ST'       => 'st',
																	'CUR_ST_VAL'   => $this->ipsclass->input['st'],
																	'L_SINGLE'     => "Single Page",
																	'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=receipt"
															)	);

		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->html .= "<br />";
		
		$this->ipsclass->adskin->td_header[] = array( "IP Address"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "Member"      , "" );
		$this->ipsclass->adskin->td_header[] = array( "Time"        , "" );
		$this->ipsclass->adskin->td_header[] = array( "Method"      , "" );
		$this->ipsclass->adskin->td_header[] = array( "Items"       , "" );
		$this->ipsclass->adskin->td_header[] = array( "Total"       , "" );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("List of receipts");
		
		$tranlate = array('buy'=>"Buying",'resell'=>"Resell");
		$field = array('buy'=>"total_price",'resell'=>"total_resell");
		
		$this->ipsclass->DB->build_query(array(
												'select' => 'bl.ip_address, bl.method, bl.time_bought, bl.member_id, SUM(bl.quanity) as total_quanity, SUM((bl.price_bought+bl.tax_total)*bl.quanity) as total_price, SUM(bl.resell_price*bl.quanity) as total_resell',
												'from' => array('market_buy_logs'=>'bl'),
												'add_join' => array(
																		array(
																				'select' => 'm.members_display_name, m.mgroup',
																				'from' => array('members'=>'m'),
																				'where' => 'm.id=bl.member_id',
																				'type' => 'left',
																			),
																	),
												'group' => 'bl.time_bought, bl.method, bl.member_id',
												'order' => 'bl.time_bought DESC',
												'limit' => array($this->ipsclass->input['st'],$this->LIMIT)
										)	);
		$this->ipsclass->DB->exec_query();
		while($receipt = $this->ipsclass->DB->fetch_row())
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  $receipt['ip_address'],
																				  $this->ipsclass->market_admin->format_name($receipt['member_id'],$receipt['members_display_name'],$receipt['mgroup']),
																				  $this->ipsclass->get_date($receipt['time_bought'],'LONG'),
																				  $tranlate[$receipt['method']],
																				  $this->ipsclass->do_number_format($receipt['total_quanity']),
																				  $this->ipsclass->numbers->format_currency($receipt[$field[$receipt['method']]]),
																		 )      );
		}
		if($this->ipsclass->DB->get_num_rows() == 0)
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No item logs",'center');
		}
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->admin->output();
	}
	
	function item_logs()
	{
		$this->ipsclass->input['st'] = intval($this->ipsclass->input['st']);
		
		$this->ipsclass->admin->page_title  = "Welcome to item logs page";
		$this->ipsclass->admin->page_detail = "Welcome to item logs page";
		$this->ipsclass->admin->nav[] 		= array( $this->ipsclass->form_code.'&amp;code=logs&amp;do=item', 'Item Logs' );
		
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_item_logs'));
		$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																	'PER_PAGE'     => $this->LIMIT,
																	'USE_ST'       => 'st',
																	'CUR_ST_VAL'   => $this->ipsclass->input['st'],
																	'L_SINGLE'     => "Single Page",
																	'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=item"
															)	);

		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->html .= "<br />";
		
		$this->ipsclass->adskin->td_header[] = array( "Item"        , "" );
		$this->ipsclass->adskin->td_header[] = array( "IP Address"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "Member"      , "" );
		$this->ipsclass->adskin->td_header[] = array( "Time"        , "" );
		$this->ipsclass->adskin->td_header[] = array( "Message"     , "" );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Item Logs");
		
		$this->ipsclass->DB->build_query(array(
												'select' => 'l.*',
												'from' => array('market_item_logs'=>'l'),
												'add_join' => array(
																		array(
																				'select' => 'm.members_display_name, m.mgroup',
																				'from' => array('members'=>'m'),
																				'where' => "m.id=l.member_id",
																				'type' => 'left'
																			),
																	),
												'order' => 'l_id DESC',
												'limit' => array($this->ipsclass->input['st'],$this->LIMIT)
										)	);
		$this->ipsclass->DB->exec_query();
		while($log = $this->ipsclass->DB->fetch_row())
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  $this->ipsclass->cache['market_items'][$log['item_id']]['item_name'],
																				  $log['ip_address'],
																				  $this->ipsclass->market_admin->format_name($log['member_id'],$log['members_display_name'],$log['mgroup']),
																				  $this->ipsclass->get_date($log['l_time'],'LONG'),
																				  $log['log_message']
																		 )      );
		}
		if($this->ipsclass->DB->get_num_rows() == 0)
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No item logs",'center');
		}
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->admin->output();
	}
	
	function reward_logs()
	{
		$this->ipsclass->input['st'] = intval($this->ipsclass->input['st']);
		
		$this->ipsclass->admin->page_title  = "Welcome to reward log page for the ibMarket";
		$this->ipsclass->admin->page_detail = "Welcome to reward log page for the ibMarket.";
		$this->ipsclass->admin->nav[] 		= array( $this->ipsclass->form_code.'&amp;code=logs&amp;do=reward', 'Reward Logs' );
		
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_reward_logs'));
		$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																	'PER_PAGE'     => $this->LIMIT,
																	'USE_ST'       => 'st',
																	'CUR_ST_VAL'   => $this->ipsclass->input['st'],
																	'L_SINGLE'     => "Single Page",
																	'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=reward"
															)	);

		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->html .= "<br />";
		
		$this->ipsclass->adskin->td_header[] = array( "Member"          , "" );
		$this->ipsclass->adskin->td_header[] = array( "Time"            , "" );
		$this->ipsclass->adskin->td_header[] = array( "Location/Reason" , "" );
		$this->ipsclass->adskin->td_header[] = array( "Amount"          , "" );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Reward Logs");
		
		$this->ipsclass->DB->build_query(array(
												'select' => 'l.*',
												'from' => array('market_reward_logs'=>'l'),
												'add_join' => array(
																		array(
																				'select' => 'm.members_display_name, m.mgroup',
																				'from' => array('members'=>'m'),
																				'where' => "m.id=l.member_id",
																				'type' => 'left'
																			),
																	),
												'order' => 'l_time DESC',
												'limit' => array($this->ipsclass->input['st'],$this->LIMIT)
										)	);
		$this->ipsclass->DB->exec_query();
		while($log = $this->ipsclass->DB->fetch_row())
		{
			$reason = "";
			if($log['location'] == 'registered')
			{
				$reason = "Registration bonus";
			}
			elseif($log['location'] == 'posts')
			{
				$reason = "Post rewards";
			}
			elseif(strstr($log['location'],'plugin:') === $log['location'])
			{
				$info = explode(":",$log['location']);
				if(is_array($this->ipsclass->cache['market_plugin'][$info[1]]))
				{
					$info[2] = $this->ipsclass->cache['market_plugin'][$info[1]]['name'];
				}
				$reason = "From plugin ".$info[2];
			}
			elseif(strstr($log['location'],'item:') === $log['location'])
			{
				$info = explode(":",$log['location']);
				if(is_array($this->ipsclass->cache['market_items'][$info[1]]))
				{
					$info[2] = $this->ipsclass->cache['market_items'][$info[1]]['item_name'];
				}
				$reason = "From item ".$info[2];
			}
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  
																				  $this->ipsclass->market_admin->format_name($log['member_id'],$log['members_display_name'],$log['mgroup']),
																				  $this->ipsclass->get_date($log['l_time'],'LONG'),
																				  $reason,
																				  $this->ipsclass->numbers->format_currency($log['l_amount']),
																		 )      );
		}
		if($this->ipsclass->DB->get_num_rows() == 0)
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No reward logs",'center');
		}
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->admin->output();
	}
	
	function fee_logs()
	{
		$this->ipsclass->input['st'] = intval($this->ipsclass->input['st']);
		
		$this->ipsclass->admin->page_title  = "Welcome to fee log page for the ibMarket";
		$this->ipsclass->admin->page_detail = "Welcome to fee log page for the ibMarket.";
		$this->ipsclass->admin->nav[] 		= array( $this->ipsclass->form_code.'&amp;code=logs&amp;do=fee', 'Fee Logs' );
		
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_fee_logs'));
		$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																	'PER_PAGE'     => $this->LIMIT,
																	'USE_ST'       => 'st',
																	'CUR_ST_VAL'   => $this->ipsclass->input['st'],
																	'L_SINGLE'     => "Single Page",
																	'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=reward"
															)	);

		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->html .= "<br />";
		
		$this->ipsclass->adskin->td_header[] = array( "Member"          , "" );
		$this->ipsclass->adskin->td_header[] = array( "Time"            , "" );
		$this->ipsclass->adskin->td_header[] = array( "Location/Reason" , "" );
		$this->ipsclass->adskin->td_header[] = array( "Amount"          , "" );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Fee Logs");
		
		$this->ipsclass->DB->build_query(array(
												'select' => 'l.*',
												'from' => array('market_fee_logs'=>'l'),
												'add_join' => array(
																		array(
																				'select' => 'm.members_display_name, m.mgroup',
																				'from' => array('members'=>'m'),
																				'where' => "m.id=l.member_id",
																				'type' => 'left'
																			),
																	),
												'order' => 'l_time DESC',
												'limit' => array($this->ipsclass->input['st'],$this->LIMIT)
										)	);
		$this->ipsclass->DB->exec_query();
		while($log = $this->ipsclass->DB->fetch_row())
		{
			$reason = "";
			if($log['location'] == 'buy')
			{
				$reason = "Item Taxes";
			}
			elseif(strstr($log['location'],'plugin:') === $log['location'])
			{
				$info = explode(":",$log['location']);
				if(is_array($this->ipsclass->cache['market_plugin'][$info[1]]))
				{
					$info[2] = $this->ipsclass->cache['market_plugin'][$info[1]]['name'];
				}
				$reason = "From plugin ".$info[2];
			}
			elseif(strstr($log['location'],'item:') === $log['location'])
			{
				$info = explode(":",$log['location']);
				if(is_array($this->ipsclass->cache['market_items'][$info[1]]))
				{
					$info[2] = $this->ipsclass->cache['market_items'][$info[1]]['item_name'];
				}
				$reason = "From item ".$info[2];
			}
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  
																				  $this->ipsclass->market_admin->format_name($log['member_id'],$log['members_display_name'],$log['mgroup']),
																				  $this->ipsclass->get_date($log['l_time'],'LONG'),
																				  $reason,
																				  $this->ipsclass->numbers->format_currency($log['l_amount']),
																		 )      );
		}
		if($this->ipsclass->DB->get_num_rows() == 0)
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No fee logs",'center');
		}
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->admin->output();
	}
	
	function ip_address_search_logs()
	{
		if ( $this->ipsclass->input['ip_address'] == "" )
		{
			$this->ipsclass->main_msg = "You need to enter an IP address";
			$this->ipsclass->admin->redirect_noscreen($this->ipsclass->base_url."&".$this->ipsclass->form_code);
		}
		
		$ip = trim($this->ipsclass->input['ip_address']);
		$exact    = 0;
		
		if ( substr_count( $ip, '.' ) == 3 )
		{
			$exact = 1;
		}
		if ( strstr( $ip, '*' ) )
		{
			$exact = 0;
			$ip    = str_replace( "*", "%", $ip );
		}
		if ( $exact != 0 )
		{
			$query    = "='".$ip."'";
		}
		else
		{
			$query    = " LIKE '".$ip."'";
		}
		
		$this->ipsclass->input['st_r'] = intval($this->ipsclass->input['st_r']);
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(DISTINCT time_bought, method, member_id) as total','from'=>'market_buy_logs','where'=>"ip_address".$query));
		$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																	'PER_PAGE'     => $this->LIMIT,
																	'USE_ST'       => 'st_r',
																	'CUR_ST_VAL'   => $this->ipsclass->input['st_r'],
																	'L_SINGLE'     => "Single Page",
																	'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
															)	);
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->html .= "<br />";
		
		$this->ipsclass->adskin->td_header[] = array( "IP Address"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "Member"      , "" );
		$this->ipsclass->adskin->td_header[] = array( "Time"        , "" );
		$this->ipsclass->adskin->td_header[] = array( "Method"      , "" );
		$this->ipsclass->adskin->td_header[] = array( "Items"       , "" );
		$this->ipsclass->adskin->td_header[] = array( "Total"       , "" );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Receipts");
		
		$tranlate = array('buy'=>"Buying",'resell'=>"Resell");
		$field = array('buy'=>"total_price",'resell'=>"total_resell");
		
		$this->ipsclass->DB->build_query(array(
												'select' => 'bl.ip_address, bl.method, bl.time_bought, bl.member_id, SUM(bl.quanity) as total_quanity, SUM((bl.price_bought+bl.tax_total)*bl.quanity) as total_price, SUM(bl.resell_price*bl.quanity) as total_resell',
												'from' => array('market_buy_logs'=>'bl'),
												'add_join' => array(
																		array(
																				'select' => 'm.members_display_name, m.mgroup',
																				'from' => array('members'=>'m'),
																				'where' => 'm.id=bl.member_id',
																				'type' => 'left',
																			),
																	),
												'where' => 'bl.ip_address'.$query,
												'group' => 'bl.time_bought, bl.method, bl.member_id',
												'order' => 'bl.time_bought DESC',
												'limit' => array($this->ipsclass->input['st_r'],$this->IP_LIMIT),
										)	);
		$this->ipsclass->DB->exec_query();
		while($receipt = $this->ipsclass->DB->fetch_row())
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  $receipt['ip_address'],
																				  $this->ipsclass->market_admin->format_name($receipt['member_id'],$receipt['members_display_name'],$receipt['mgroup']),
																				  $this->ipsclass->get_date($receipt['time_bought'],'LONG'),
																				  $tranlate[$receipt['method']],
																				  $this->ipsclass->do_number_format($receipt['total_quanity']),
																				  $this->ipsclass->numbers->format_currency($receipt[$field[$receipt['method']]]),
																		 )      );
		}
		if($this->ipsclass->DB->get_num_rows() == 0)
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No receipts",'center');
		}
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->input['st_i'] = intval($this->ipsclass->input['st_i']);
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_item_logs','where'=>"ip_address".$query));
		$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																	'PER_PAGE'     => $this->LIMIT,
																	'USE_ST'       => 'st_i',
																	'CUR_ST_VAL'   => $this->ipsclass->input['st_i'],
																	'L_SINGLE'     => "Single Page",
																	'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
															)	);
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
		
		$this->ipsclass->html .= "<br />";
		
		$this->ipsclass->adskin->td_header[] = array( "Item"        , "" );
		$this->ipsclass->adskin->td_header[] = array( "IP Address"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "Member"      , "" );
		$this->ipsclass->adskin->td_header[] = array( "Time"        , "" );
		$this->ipsclass->adskin->td_header[] = array( "Message"     , "" );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Item Logs");
		
		$this->ipsclass->DB->build_query(array(
												'select' => 'l.*',
												'from' => array('market_item_logs'=>'l'),
												'add_join' => array(
																		array(
																				'select' => 'm.members_display_name, m.mgroup',
																				'from' => array('members'=>'m'),
																				'where' => "m.id=l.member_id",
																				'type' => 'left'
																			),
																	),
												'where' => "l.ip_address".$query,
												'order' => 'l.l_id DESC',
												'limit' => array($this->ipsclass->input['st_i'],$this->IP_LIMIT)
										)	);
		$this->ipsclass->DB->exec_query();
		while($log = $this->ipsclass->DB->fetch_row())
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  $this->ipsclass->cache['market_items'][$log['item_id']]['item_name'],
																				  $log['ip_address'],
																				  $this->ipsclass->market_admin->format_name($log['member_id'],$log['members_display_name'],$log['mgroup']),
																				  $this->ipsclass->get_date($log['l_time'],'LONG'),
																				  $log['log_message']
																		 )      );
		}
		if($this->ipsclass->DB->get_num_rows() == 0)
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No item logs",'center');
		}
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		if($this->ipsclass->market_class->count_plugin_filename("bank.php"))
		{
			$this->ipsclass->input['st_b'] = intval($this->ipsclass->input['st_b']);
			$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_bank_transactions','where'=>"l_ip_address".$query." AND l_action != 'interest'"));
			$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																		'PER_PAGE'     => $this->LIMIT,
																		'USE_ST'       => 'st_b',
																		'CUR_ST_VAL'   => $this->ipsclass->input['st_b'],
																		'L_SINGLE'     => "Single Page",
																		'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
																)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
			
			$this->ipsclass->html .= "<br />";
			
			$this->ipsclass->adskin->td_header[] = array( "Account ID"  , "35%" );
			$this->ipsclass->adskin->td_header[] = array( "IP Address"  , "15%" );
			$this->ipsclass->adskin->td_header[] = array( "Time"        , "15%" );
			$this->ipsclass->adskin->td_header[] = array( "Action"      , "35%" );
			
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Transaction Logs");
			
			$this->ipsclass->DB->build_query(array(
														'select' => '*',
														'from' => 'market_bank_transactions',
														'where' => "l_ip_address".$query." AND l_action != 'interest'",
														'order' => 'l_timestamp DESC',
														'limit' => array($this->ipsclass->input['st_b'],$this->IP_LIMIT)
											)		);
			$this->ipsclass->DB->exec_query();
			while($log = $this->ipsclass->DB->fetch_row())
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  $log['l_account_id'],
																					  $log['l_ip_address'],
																					  $this->ipsclass->get_date($log['l_timestamp'],'LONG'),
																					  ucfirst($log['l_action']),
																			 )      );
			}
			if($this->ipsclass->DB->get_num_rows() == 0)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No bank transaction",'center');
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		
		if($this->ipsclass->market_class->count_plugin_filename("transfer.php"))
		{
			$this->ipsclass->input['st_t'] = intval($this->ipsclass->input['st_t']);
			$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_transfer_logs','where'=>"l_ip_address".$query));
			$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																		'PER_PAGE'     => $this->LIMIT,
																		'USE_ST'       => 'st_t',
																		'CUR_ST_VAL'   => $this->ipsclass->input['st_t'],
																		'L_SINGLE'     => "Single Page",
																		'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
																)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
			
			$this->ipsclass->html .= "<br />";
			
			$this->ipsclass->adskin->td_header[] = array( "LINK ID"             , "" );
			$this->ipsclass->adskin->td_header[] = array( "When"                , "" );
			$this->ipsclass->adskin->td_header[] = array( "From's IP"           , "" );
			$this->ipsclass->adskin->td_header[] = array( "From"                , "" );
			$this->ipsclass->adskin->td_header[] = array( "To"                  , "" );
			$this->ipsclass->adskin->td_header[] = array( "Money Amount"    	, "" );
			$this->ipsclass->adskin->td_header[] = array( "Number of Items" 	, "" );
			
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Transfer Logs");
			
			$this->ipsclass->DB->build_query(array(
														'select' => 'l.*',
														'from' => array('market_transfer_logs'=>'l'),
														'add_join' => array(
																				array(
																						'select' => 't.members_display_name as to_name, t.mgroup as to_group',
																						'from' => array('members'=>'t'),
																						'where' => "t.id=l.l_to",
																						'type' => 'left',
																					),
																				array(
																						'select' => 'f.members_display_name as from_name, f.mgroup as from_group',
																						'from' => array('members'=>'f'),
																						'where' => "f.id=l.l_from",
																						'type' => 'left',
																					),
																			),
														'where' => "l.l_ip_address".$query,
														'order' => 'l_time DESC',
														'limit' => array($this->ipsclass->input['st_t'],$this->IP_LIMIT)
											)		);
			$this->ipsclass->DB->exec_query();
			$logs = array();
			while($log = $this->ipsclass->DB->fetch_row())
			{
				$log['item_count'] = 0;
				$log['to_name'] = $this->ipsclass->market_admin->format_name($log['l_to'],$log['to_name'],$log['to_group']);
				$log['from_name'] = $this->ipsclass->market_admin->format_name($log['l_from'],$log['from_name'],$log['from_group']);
				$logs[$log['l_id']] = $log;
			}
			
			if(count($logs))
			{
				$this->ipsclass->DB->build_query_from_cache('transfer_count_item_logs',array('log_ids'=>array_keys($logs)),'sql_plugin_queries');
				$this->ipsclass->DB->exec_query();
				while($item_log = $this->ipsclass->DB->fetch_row())
				{
					$logs[$item_log['log_id']]['item_count'] = $item_log['total'];
				}
			}
			
			foreach($logs as $log)
			{
				$row = array( "<a href='".$this->ipsclass->vars['board_url']."/index.".$this->ipsclass->vars['php_ext']."?autocom=market&amp;plugin=".$log['l_link']."' target='_blank'>".$log['l_link']."</a>",
							  $this->ipsclass->get_date($log['l_time'],'SHORT'),
							  $log['l_ip_address'],
							  $log['from_name'],
							  $log['to_name'],
							  $this->ipsclass->numbers->format_currency($log['l_amount']),
							  $log['item_count'],
							);
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( $row );
			}
			if($this->ipsclass->DB->get_num_rows() == 0)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No transfer logs",'center');
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		
		if($this->ipsclass->market_class->count_plugin_filename("converter.php"))
		{
			$this->ipsclass->input['st_c'] = intval($this->ipsclass->input['st_c']);
			$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_converter_logs','where'=>"l_ip_address".$query));
			$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																		'PER_PAGE'     => $this->LIMIT,
																		'USE_ST'       => 'st_c',
																		'CUR_ST_VAL'   => $this->ipsclass->input['st_c'],
																		'L_SINGLE'     => "Single Page",
																		'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
																)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
			
			$this->ipsclass->html .= "<br />";
			
			$this->ipsclass->adskin->td_header[] = array( "LINK ID"    , "" );
			$this->ipsclass->adskin->td_header[] = array( "When"       , "" );
			$this->ipsclass->adskin->td_header[] = array( "Member"     , "" );
			$this->ipsclass->adskin->td_header[] = array( "IP Address" , "" );
			$this->ipsclass->adskin->td_header[] = array( "Direction"  , "" );
			$this->ipsclass->adskin->td_header[] = array( "Amount"     , "" );
			
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Conversion Logs");
			
			$this->ipsclass->DB->build_query(array(
														'select' => 'l.*',
														'from' => array('market_converter_logs'=>'l'),
														'add_join' => array(
																				array(
																						'select' => 'm.members_display_name, m.mgroup',
																						'from' => array('members'=>'m'),
																						'where' => "m.id=l.l_member_id",
																						'type' => 'left',
																					),
																			),
														'where' => "l.l_ip_address".$query,
														'order' => 'l_time DESC',
														'limit' => array($this->ipsclass->input['st'],$this->IP_LIMIT)
											)		);
			$this->ipsclass->DB->exec_query();
			while($log = $this->ipsclass->DB->fetch_row())
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  "<a href='".$this->ipsclass->vars['board_url']."/index.".$this->ipsclass->vars['php_ext']."?autocom=market&amp;plugin=".$log['l_link']."' target='_blank'>".$log['l_link']."</a>",
																					  $this->ipsclass->get_date($log['l_time'],'LONG'),
																					  $this->ipsclass->market_class->format_name($log['member_id'],$log['members_display_name'],$log['mgroup']),
																					  $log['l_ip_address'],
																					  ucfirst($log['l_direction'])." ibMarket Money",
																					  $this->ipsclass->do_number_format($log['l_amount']),
																			 )      );
			}
			if($this->ipsclass->DB->get_num_rows() == 0)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No converting logs",'center');
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		
		if($this->ipsclass->market_class->count_plugin_filename("scratchcard.php"))
		{
			$link = "";
			if(is_array($this->ipsclass->cache['market_plugin']) && count($this->ipsclass->cache['market_plugin']))
			{
				foreach($this->ipsclass->cache['market_plugin'] as $l => $plugin)
				{
					if($plugin['filename'] == "scratchcard.php")
					{
						$link = $l;
					}
				}
			}
			$this->ipsclass->input['st_s'] = intval($this->ipsclass->input['st_s']);
			$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_scratchcard_ticket','where'=>"ip_address".$query));
			$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																		'PER_PAGE'     => $this->LIMIT,
																		'USE_ST'       => 'st_s',
																		'CUR_ST_VAL'   => $this->ipsclass->input['st_s'],
																		'L_SINGLE'     => "Single Page",
																		'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
																)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
			
			$this->ipsclass->html .= "<br />";
			
			$this->ipsclass->html .= "<script type=\"text/javascript\">
function display_ticket(id,x,y)
{
	window.open(\"{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=plugin&do=run&link={$link}&action=ticket&runme=display&ticket=\" + id, \"\", \"scrollbars=no,address=no,toolbar=no,status=yes,width=\" + x + \",height=\" + y);
}
</script>";
		
			$this->ipsclass->adskin->td_header[] = array( "Member"   , "" );
			$this->ipsclass->adskin->td_header[] = array( "Card"     , "" );
			$this->ipsclass->adskin->td_header[] = array( "Bought"   , "" );
			$this->ipsclass->adskin->td_header[] = array( "Status"   , "" );
			$this->ipsclass->adskin->td_header[] = array( "Win/Lose" , "" );
			
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Scratchcard Tickets");
			
			$this->ipsclass->DB->build_query(array(
														'select' => 't.*',
														'from' => array('market_scratchcard_ticket'=>'t'),
														'where' => "t.ip_address".$query,
														'add_join' => array(
																				array(
																						'select' => 'm.members_display_name, m.mgroup',
																						'from' => array('members'=>'m'),
																						'where' => 'm.id=t.member_id',
																						'type' => 'left',
																					),
																			),
														'order' => 'time_created DESC',
														'limit' => array($this->ipsclass->input['st'],$this->IP_LIMIT)
											)		);
			$this->ipsclass->DB->exec_query();
			while($ticket = $this->ipsclass->DB->fetch_row())
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  $this->ipsclass->market_admin->format_name($ticket['member_id'],$ticket['members_display_name'],$ticket['mgroup']),
																					  $this->ipsclass->cache['ibm_scratchcard'][$ticket['card_id']]['name'],
																					  $this->ipsclass->get_date($ticket['time_created'],'LONG'),
																					  "<a href=\"javascript:void(0);\" onclick=\"display_ticket({$ticket['tick_id']},{$this->ipsclass->cache['ibm_scratchcard'][$ticket['card_id']]['size_width']},{$this->ipsclass->cache['ibm_scratchcard'][$ticket['card_id']]['size_height']});\">".($ticket['used'] == 0 ? "Unfinished" : "Used")."</a>",
																					  $ticket['won'] == 0 ? "Lose" : "Won",
																			 )      );
			}
			if($this->ipsclass->DB->get_num_rows() == 0)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No scratchcard ticket",'center');
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		
		if($this->ipsclass->market_class->count_plugin_filename("auction.php"))
		{
			$link = "";
			if(is_array($this->ipsclass->cache['market_plugin']) && count($this->ipsclass->cache['market_plugin']))
			{
				foreach($this->ipsclass->cache['market_plugin'] as $l => $plugin)
				{
					if($plugin['filename'] == "auction.php")
					{
						$link = $l;
					}
				}
			}
			$this->ipsclass->input['st_a'] = intval($this->ipsclass->input['st_a']);
			$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_auction_item','where'=>"ip_address".$query));
			$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																		'PER_PAGE'     => $this->LIMIT,
																		'USE_ST'       => 'st_a',
																		'CUR_ST_VAL'   => $this->ipsclass->input['st_a'],
																		'L_SINGLE'     => "Single Page",
																		'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
																)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
			
			$this->ipsclass->html .= "<br />";
			
			$this->ipsclass->adskin->td_header[] = array( "Icon"             , "1%"  );
			$this->ipsclass->adskin->td_header[] = array( "Name/Description" , "50%" );
			$this->ipsclass->adskin->td_header[] = array( "IP Address"       , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Seller"           , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Bids/Time Ending" , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Bidder/Price"     , ""    );
			
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Auction Items");
			
			$this->ipsclass->DB->build_query(array(
													'select' => 'i.*',
													'from' => array('market_auction_item'=>'i'),
													'add_join' => array(
																			array(
																					'select' => 'COUNT(b.b_id) as num_bids',
																					'from' => array('market_auction_bids'=>'b'),
																					'where' => 'i.a_id=b.aitem_id',
																					'type' => 'left',
																				),
																			array(
																					'select' => 's.members_display_name as seller_name, s.mgroup as seller_group',
																					'from' => array('members'=>'s'),
																					'where' => 's.id=i.member_id',
																					'type' => 'left',
																				),
																			array(
																					'select' => 'm.members_display_name as bidder_name, m.mgroup as bidder_group',
																					'from' => array('members'=>'b'),
																					'where' => 'm.id=i.highest_id',
																					'type' => 'left',
																				),
																		),
													'where' => 'i.ip_address'.$query,
													'group' => 'i.a_id',
													'order' => 'time_end DESC',
													'limit' => array($this->ipsclass->input['st_a'],$this->IP_LIMIT),
											)	);
			$this->ipsclass->DB->exec_query();
			while($item = $this->ipsclass->DB->fetch_row())
			{
				$item['num_bid'] = $item['num_bids'];
				$item['num_bids'] = $this->ipsclass->do_number_format($item['num_bids']).($item['num_bids'] == 1 ? " Bid" : " Bids");
				$item['highest_bid'] = $this->ipsclass->numbers->format_currency($item['highest_bid']);
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  
																					  "<img src='".$this->ipsclass->market_class->image_url_path."/icons/".$this->ipsclass->cache['market_items'][$item['item']]['icon']."' border='0' alt='Item Icon' />",
																					  "<a href='".$this->ipsclass->vars['board_url']."/index.".$this->ipsclass->vars['php_ext']."?autocom=market&amp;plugin=".$link."&amp;do=item&amp;item=".$item['a_id']."'><b>".$this->ipsclass->cache['market_items'][$item['item']]['item_name']."</b></a><br />".$this->ipsclass->parser->pre_display_parse($this->ipsclass->parser->pre_db_parse($this->ipsclass->market_class->items_loaded[$item['item']]->parse_single_description($item))),
																					  $item['ip_address'],
																					  $this->ipsclass->market_admin->format_name($item['member_id'],$item['seller_name'],$item['seller_group']),
																					  "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=plugin&amp;do=run&amp;link={$link}&amp;item=".$item['a_id']."&amp;action=bids'>".$item['num_bids']."</a><br />".$this->ipsclass->get_date($item['time_end'],'LONG'),
																					  ($item['num_bid'] == 0 ? "---" : $this->ipsclass->market_admin->format_name($item['highest_id'],$item['bidder_name'],$item['bidder_group']))."<br />".$item['highest_bid'],
																			 )      );
			}
			if($this->ipsclass->DB->get_num_rows() == 0)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No auction items",'center');
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
			
			$this->ipsclass->input['st_d'] = intval($this->ipsclass->input['st_d']);
			$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_auction_bids','where'=>"ip_address".$query));
			$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																		'PER_PAGE'     => $this->LIMIT,
																		'USE_ST'       => 'st_d',
																		'CUR_ST_VAL'   => $this->ipsclass->input['st_d'],
																		'L_SINGLE'     => "Single Page",
																		'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
																)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
			
			$this->ipsclass->html .= "<br />";
			
			$this->ipsclass->adskin->td_header[] = array( "Icon"             , "1%"  );
			$this->ipsclass->adskin->td_header[] = array( "Name/Description" , "50%" );
			$this->ipsclass->adskin->td_header[] = array( "IP Address"       , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Bidder"           , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Bids Time"        , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Bid Price"        , ""    );
			
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Auction Bids");
			
			$this->ipsclass->DB->build_query(array(
														'select' => 'b.*, b.ip_address as the_ip',
														'from' => array('market_auction_bids'=>'b'),
														'where' => "b.ip_address".$query,
														'add_join' => array(
																				array(
																						'select' => 'i.*',
																						'from' => array('market_auction_item'=>'i'),
																						'where' => "b.aitem_id=i.a_id",
																						'type' => 'left',
																					),
																				array(
																						'select' => 'm.members_display_name, m.mgroup',
																						'from' => array('members'=>'m'),
																						'where' => "m.id=b.member_id",
																						'type' => 'left',
																					),
																			),
														'order' => 'b.bid_time DESC',
														'limit' => array($this->ipsclass->input['st_d'],$this->IP_LIMIT)
											)		);
			$this->ipsclass->DB->exec_query();
			while($item = $this->ipsclass->DB->fetch_row())
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  
																					  "<img src='".$this->ipsclass->market_class->image_url_path."/icons/".$this->ipsclass->cache['market_items'][$item['item']]['icon']."' border='0' alt='Item Icon' />",
																					  "<a href='".$this->ipsclass->vars['board_url']."/index.".$this->ipsclass->vars['php_ext']."?autocom=market&amp;plugin=".$link."&amp;do=item&amp;item=".$item['a_id']."'><b>".$this->ipsclass->cache['market_items'][$item['item']]['item_name']."</b></a><br />".$this->ipsclass->parser->pre_display_parse($this->ipsclass->parser->pre_db_parse($this->ipsclass->market_class->items_loaded[$item['item']]->parse_single_description($item))),
																					  $item['the_ip'],
																					  $this->ipsclass->market_admin->format_name($item['member_id'],$item['members_display_name'],$item['mgroup']),
																					  $this->ipsclass->get_date($item['bid_time'],'LONG'),
																					  $this->ipsclass->numbers->format_currency($item['highest_bid']),
																			 )      );
			}
			if($this->ipsclass->DB->get_num_rows() == 0)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No auction bids made",'center');
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		
		if($this->ipsclass->market_class->count_plugin_filename("userstore.php"))
		{
			$this->ipsclass->input['st_ui'] = intval($this->ipsclass->input['st_ui']);
			$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_user_store_item','where'=>"ip_address".$query));
			$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																		'PER_PAGE'     => $this->LIMIT,
																		'USE_ST'       => 'st_ui',
																		'CUR_ST_VAL'   => $this->ipsclass->input['st_ui'],
																		'L_SINGLE'     => "Single Page",
																		'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
																)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
			
			$this->ipsclass->html .= "<br />";
			
			$this->ipsclass->adskin->td_header[] = array( "Icon"             , "1%"  );
			$this->ipsclass->adskin->td_header[] = array( "Name/Description" , "50%" );
			$this->ipsclass->adskin->td_header[] = array( "IP Address"       , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Seller"           , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Store Price"      , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Listed On"        , ""    );
			
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Selling User Store Items");
			
			$this->ipsclass->DB->build_query(array(
													'select' => 'i.*',
													'from' => array('market_user_store_item'=>'i'),
													'where'=>"i.ip_address".$query,
													'add_join' => array(
																			array(
																					'select' => 'm.members_display_name as seller_name,m.mgroup as seller_group',
																					'from' => array('members'=>'m'),
																					'where' => "m.id=i.member_id",
																					'type' => 'left',
																				),
																		),
													'order' => 'i.listed DESC',
													'limit' => array($this->ipsclass->input['st'],$this->IP_LIMIT),
											)	);
			$this->ipsclass->DB->exec_query();
			while($item = $this->ipsclass->DB->fetch_row())
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  
																					  "<img src='".$this->ipsclass->market_class->image_url_path."/icons/".$this->ipsclass->cache['market_items'][$item['item']]['icon']."' border='0' alt='Item Icon' />",
																					  "<b>".$this->ipsclass->cache['market_items'][$item['item']]['item_name']."</b><br />".$this->ipsclass->parser->pre_display_parse($this->ipsclass->parser->pre_db_parse($this->ipsclass->market_class->items_loaded[$item['item']]->parse_single_description($item))),
																					  $item['ip_address'],
																					  $this->ipsclass->market_admin->format_name($item['member_id'], $item['seller_name'],$item['seller_group']),
																					  $this->ipsclass->numbers->format_currency($item['store_price']),
																					  $this->ipsclass->get_date($item['listed'],'LONG'),
																			 )      );
			}
			if($this->ipsclass->DB->get_num_rows() == 0)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No user store items selling",'center');
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
			
			$this->ipsclass->input['st_ub'] = intval($this->ipsclass->input['st_ub']);
			$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_user_store_logs','where'=>"buyer_ip".$query));
			$page = $this->ipsclass->adskin->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																		'PER_PAGE'     => $this->LIMIT,
																		'USE_ST'       => 'st_ub',
																		'CUR_ST_VAL'   => $this->ipsclass->input['st_ub'],
																		'L_SINGLE'     => "Single Page",
																		'BASE_URL'     => $this->ipsclass->base_url."&amp;".$this->ipsclass->form_code."&amp;code=logs&amp;do=ip&amp;ip_address=".$this->ipsclass->input['ip_address']
																)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->add_standalone_row($page,"left");
			
			$this->ipsclass->html .= "<br />";
			
			$this->ipsclass->adskin->td_header[] = array( "Icon"             , "1%"  );
			$this->ipsclass->adskin->td_header[] = array( "Name/Description" , "50%" );
			$this->ipsclass->adskin->td_header[] = array( "Seller"           , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Buyer"            , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Buyer's IP"       , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Price"            , ""    );
			$this->ipsclass->adskin->td_header[] = array( "Bought On"        , ""    );
			
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Sold User Store Items");
			
			$this->ipsclass->DB->build_query(array(
													'select' => 'i.*',
													'from' => array('market_user_store_logs'=>'i'),
													'where'=>"i.buyer_ip".$query,
													'add_join' => array(
																			array(
																					'select' => 's.members_display_name as seller_name,s.mgroup as seller_group',
																					'from' => array('members'=>'s'),
																					'where' => "s.id=i.seller_id",
																					'type' => 'left',
																				),
																			array(
																					'select' => 'b.members_display_name as buyer_name,b.mgroup as buyer_group',
																					'from' => array('members'=>'b'),
																					'where' => "b.id=i.buyer_id",
																					'type' => 'left',
																				),
																		),
													'order' => 'i.time_bought DESC',
													'limit' => array($this->ipsclass->input['st'],$this->IP_LIMIT),
											)	);
			$this->ipsclass->DB->exec_query();
			while($item = $this->ipsclass->DB->fetch_row())
			{
				$item['price_bought'] = $item['price'];
				$item['resell_price'] = 0;
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(  
																					  "<img src='".$this->ipsclass->market_class->image_url_path."/icons/".$this->ipsclass->cache['market_items'][$item['item']]['icon']."' border='0' alt='Item Icon' />",
																					  "<b>".$this->ipsclass->cache['market_items'][$item['item']]['item_name']."</b><br />".$this->ipsclass->parser->pre_display_parse($this->ipsclass->parser->pre_db_parse($this->ipsclass->market_class->items_loaded[$item['item']]->parse_single_description($item))),
																					  $this->ipsclass->market_class->format_name($item['seller_id'],$item['seller_name'],$item['seller_group']),
																					  $this->ipsclass->market_class->format_name($item['buyer_id'],$item['buyer_name'],$item['buyer_group']),
																					  $item['buyer_ip'],
																					  $this->ipsclass->numbers->format_currency($item['price']),
																					  $this->ipsclass->get_date($item['time_bought'],'LONG'),
																			 )      );
			}
			if($this->ipsclass->DB->get_num_rows() == 0)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("No user store items bought",'center');
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		
		$this->ipsclass->admin->output();
	}
}
?>